package Prototype;
//深复制
public class TestPrototypeNew {
    String name;
    Gender gender;
    public TestPrototypeNew(String name, Gender gender){
        this.name = name;
        try {
            this.gender = (Gender) gender.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
    }
    public String getGender(){
        return gender.getGender();
    }
    public void display(){
        System.out.println("info "+name+" "+gender.getGender());
    }

    public Object Clone(){
        TestPrototypeNew obj = new TestPrototypeNew(name, this.gender);
        return obj;
    }
}

class Gender implements Cloneable{
    private String gender;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public Gender(String gender){
        this.gender = gender;
    }

    public String getGender(){
        return gender;
    }
}